home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1997 May: Tool Chest / Dev.CD May 97 TC.toast / Sample Code / Snippets / Memory / Cache Flushing / Cache.h < prev   
Encoding:
C/C++ Source or Header  |  1992-07-15  |  3.2 KB  |  71 lines  |  [TEXT/MPS ]

  1. /*
  2.  *    File:        Cache.h
  3.  *
  4.  *    Contains:    Prototype declaration of:
  5.  *                FlushCacheRange: a machine and system independent cache flush routine
  6.  *
  7.  *    Cache control is a highly CPU specific function.  Although some system independence
  8.  *    is achieved via use of the _HWPriv trap, this solution may not be general for all
  9.  *    hardware/system software combinations.  FlushCacheRange should solve that for
  10.  *    developers by working on all systems.
  11.  *    
  12.  *    Written by:    Dave Radcliffe
  13.  *
  14.  *    Copyright:    © 1991, 1992 by Apple Computer, Inc., all rights reserved.
  15.  *
  16.  *    Change History:
  17.  *
  18.  *        1/20/92        DR        Updated comments to match Cache.c
  19.  *        1/10/92        DR        Updated comments to match Cache.c
  20.  *        12/18/91    DR        New today
  21.  *
  22.  */
  23. #ifndef __CACHE__
  24. #define __CACHE__
  25. #endif
  26.  
  27. /* Prototype declaration of FlushCacheRange.  See comments for usage. */
  28. /*
  29.  * FlushCacheRange flushes both the data and instruction caches for the block of 
  30.  * memory starting at location address with size count.  Flushing the cache for 
  31.  * a range of memory is only supported on the 68040, so if this functionality is
  32.  * unavailable, the entire cache is flushed (if appropriate).
  33.  *
  34.  * If either address is NIL or count is zero, the entire cache is flushed anyway.
  35.  * Selective flushing of the cache is a time consuming process and you may wish to
  36.  * avoid it when there is no benefit to doing so.  For example, if you've recently
  37.  * manipulated a block larger than 4K (the size of the 68040 caches), selective
  38.  * flushing will probably end up flushing the entire cache anyway, so why bother?
  39.  *
  40.  * The preferred method for flushing the cache is to use the _HWPriv trap documented
  41.  * in Tech Note #261.  Some older systems may not have this trap implemented, so
  42.  * alternate methods must be used.  The first thing to try is the _CacheFlush trap.
  43.  * This was implemented beginning with the Mac II (and is also documented in Tech
  44.  * Note #261.
  45.  *
  46.  * MC68000 based systems have no cache, but if an accelerator board has been added.
  47.  * they may have a CPU which does have a cache.  Accelerator board vendors should
  48.  * implement _HWPriv or _CacheFlush for such systems, but if they haven't then
  49.  * our last resort is to write directly to the cache control register (a privileged
  50.  * instruction (GAK!!)).
  51.  *
  52.  * FINALLY, the full implementation of FlushCacheRange is probably overkill and may be 
  53.  * less than optimal for some applications.  For example, testing for _HWPriv 
  54.  * should be unnecessary on systems later than 6.0.2, so I've added conditional code
  55.  * to allow you to bypass that if appropriate (see comment on System603OrLater).
  56.  * The full implementation tries to cover a lot of obscure cases, but it also does 
  57.  * some things inefficiently.  For example, having determined the _HWPriv is 
  58.  * implemented, it would be more efficient to just keep that information around, 
  59.  * but I wanted to avoid the complications of global or static variables.  But 
  60.  * it is also true that if you find it necessary to call this code more than a
  61.  * few times between the time your application starts and the time it quits, 
  62.  * YOU ARE DOING SOMETHING WRONG!!   Go back and rethink your code.
  63. */
  64. #ifdef __cplusplus
  65. extern "C" {
  66. #endif
  67. void FlushCacheRange (void *address, unsigned long count);
  68. #ifdef __cplusplus
  69. }
  70. #endif
  71.